package cn.anjubao.cp.api.config.security;

import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

@Component
public class UserProvider implements AuthenticationProvider {
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if (authentication.isAuthenticated()) {
            return authentication;
        }
        //验证TOKEN的合法性
        UserToken userToken = (UserToken) authentication;
        userToken.setAuthenticated(true);
        return userToken;
    }

    @Override
    public boolean supports(Class<?> aClass) {
        return aClass == UserToken.class;
    }
}
